package com.twu.biblioteca;

import java.io.IOException;

/**
 * Created by kashyapk on 05/03/14.
 */
public class BookMenu extends MainMenu {

    private final Library library;
    private final Customer customer;

    public BookMenu(Library library, Customer customer) {
        super(library, customer);
        this.library = library;
        this.customer = customer;
    }

    @Override
    public void ShowMenu() {
        String menu = "1.List Books  2.Checkout Book  3.Return Book  4.Back \nEnter you choice: ";
        System.out.print(menu);
    }

    @Override
    public int MenuAction(int choice) {
        switch(choice) {
            case 1:
                for(Book book : library.ListBooks())
                    System.out.println(book.GetTitle());
                break;
            case 2:
                try {
                    System.out.print("Which book? ");
                    String bookTitle = br.readLine();
                    System.out.println(library.CheckoutBook(bookTitle, customer));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                break;
            case 3:
                try {
                    System.out.print("Which book? ");
                    String bookTitle = br.readLine();
                    System.out.println(library.ReturnBook(bookTitle, customer));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                break;
            default:
                System.out.println("Select a valid option!");
        }
        return choice;
    }
}
